module.exports = {
    /**
     * 拼接sql参数
     * key = val
     */
    handleKey(item) {
        let str = ''
        if (Array.isArray(item)) {
            let arrStr = ''
            item.map(obj => {
                for (const key in obj) {
                    arrStr += '`'+key+'`'+` = '${obj[key]}',`
                }
            })
            str = arrStr.replace(/\,$/, '')
        } else {
            for (const key in item) {
                str = `${key} = '${item[key]}'`
            }
        }
        return str
    },

    /**
     * 拼接sql参数
     * '1','2','3'
     */
    getVal: (item) => {
        let val = ''
        for (const key in item) {
            val += `'${item[key]}',`
        }
        let str = val.replace(/\,$/, '')
        return str
    },

    /**
     * 异常抛出
     */
    error: (msg = '失败', code = 400) => {
        return {
            code,
            msg
        }
    },

    /**
     * 成功返回
     */
    success: (data = {}, msg = '成功', code = 200) => {
        return {
            code,
            data,
            msg
        }
    },
}